package com.atguigu.tingshu.user.ItemTypeStrategy;

import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("1001")
public class AlbumTypeStrategyImpl implements ItemTypeStrategy {
    @Autowired
    UserFeignClient userFeignClient;
    @Autowired
    UserPaidAlbumMapper userPaidAlbumMapper;

    @Override
    public void SavePaidRecord(UserPaidRecordVo userPaidRecordVo) {
        String orderNo = userPaidRecordVo.getOrderNo();
        Long userId = userPaidRecordVo.getUserId();
        String itemType = userPaidRecordVo.getItemType();
        List<Long> itemIdList = userPaidRecordVo.getItemIdList();

        Long albumId = itemIdList.get(0);

        //购买专辑
        Boolean bolean = userFeignClient.getalbumisPaidorNot(albumId).getData();
        if (bolean) {
            //如果购买过,直接报错显示已购买
            return;
        }
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setUserId(userId);
        userPaidAlbum.setAlbumId(itemIdList.get(0));
        userPaidAlbum.setOrderNo(orderNo);
        userPaidAlbumMapper.insert(userPaidAlbum);
    }
}
